package com.wpp.algorithm.lagou.question;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wangpengpeng
 * @version 1.0
 * @description:
 * @date 2025/3/11 18:47
 */
public class A001两数之和 {

    public static int[] twoSum(int[] nums, int target) {
        Map<Integer,Integer> map = new HashMap<>();

        for(int i=0; i<=nums.length;i++) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{map.get(target - nums[i]),i};
            }
            map.put(nums[i],i);
        }

        return new int[]{};
    }

    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int target = 22;
        System.out.println(Arrays.toString(twoSum(nums, target)));
    }
}
